/*
 * @Author: Lijin
 * @Date: 2024-11-20 09:00:19
 * @LastEditors: Lijin
 * @LastEditTime: 2024-11-20 17:29:08
 * @FilePath: \electron-app\src\preload\index.js
 * @Description:
 *
 * Copyright (c) 2024 by 18323406700, All Rights Reserved.
 */
import { contextBridge, ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'

// Custom APIs for renderer
const api = {
  // 可以在这里添加自定义API
}

if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', {
      ...electronAPI,
      ipcRenderer: {
        send: ipcRenderer.send.bind(ipcRenderer),
        on: ipcRenderer.on.bind(ipcRenderer)
      }
    })
    contextBridge.exposeInMainWorld('api', api)
  } catch (error) {
    console.error(error)
  }
} else {
  window.electron = {
    ...electronAPI,
    ipcRenderer: {
      send: ipcRenderer.send.bind(ipcRenderer),
      on: ipcRenderer.on.bind(ipcRenderer)
    }
  }
  window.api = api
}
